-- LocalStorage
-- 一些乱七八糟需要存储的数据都存在这里

local DataModel = import(".DataModel")
local LocalStorage = class("LocalStorage", DataModel)

function LocalStorage:ctor()
    LocalStorage.super.ctor(self)
    self:clear()
end

function LocalStorage:clear()
    self.recommended = false -- 推荐无尽远征
    self.recommendTime = 0 -- 推荐活动隐藏的时间
    self.rankAdReportTime = 0 -- 战力排行榜前100名上次埋点时间
end

function LocalStorage:write(value)
    value.recommended = self.recommended
    value.recommendTime = self.recommendTime
    value.rankAdReportTime = self.rankAdReportTime
end

function LocalStorage:read(value)
    self.recommended = value.recommended or false
    self.recommendTime = value.recommendTime or 0
    self.rankAdReportTime = value.rankAdReportTime or 0
end

function LocalStorage:setRecommended(bool)
    self.recommended = bool
end

function LocalStorage:getRecommended()
    return self.recommended
end

function LocalStorage:setRecommendTime(time)
    self.recommendTime = time
end

function LocalStorage:getRecommendTime()
    return self.recommendTime
end

function LocalStorage:isHideRecommend()
    local flag = false
    if self.recommended then
        flag = true -- 推荐过不再显示此活动
    end
    if self.recommendTime ~= 0 then
        local days = math.floor((app.session:getServerTime() - self.recommendTime)/(24*60*60))
        if days < 7 then
            flag = true --隐藏界面不到7天不显示此活动
        end
    end
    return flag
end

function LocalStorage:setRankAdReportTime(time)
    self.rankAdReportTime = time
end

function LocalStorage:getRankAdReportTime()
    return self.rankAdReportTime
end

function LocalStorage:isRankAdReport()
    local flag = false
    if self.rankAdReportTime ~= 0 then    
        local days = math.floor((app.session:getServerTime() - self.rankAdReportTime)/(24*60*60))
        if days <= 0 then
            flag = true
        end
    end
    return flag
end

return LocalStorage